<?php
/**
 * jishupu-cms
 * @Author:技术铺<jishupu@qq.com>
 * @Date: 2021/11/11
 */

namespace App\Http\Controllers;

use App\Filters\AdminLogFilter;
use App\Http\Resources\AdminLogCollection;
use App\Models\AdminLog;
use Illuminate\Http\Request;

/**
 * 操作日志模块
 * Class AdminLogController
 * @package App\Http\Controllers
 */
class AdminLogController extends Controller
{
    /**
     * 操作日志列表
     * @param AdminLogFilter $filter
     * @return \Illuminate\Http\JsonResponse
     */
    public function index(AdminLogFilter $filter)
    {
        $paginate = AdminLog::leftJoin('user', 'admin_log.created_user_id', '=', 'user.id')->where('admin_log.type', 'basic')->select(['admin_log.*'])->filter($filter)->paginate($this->pageSize());
        $result = AdminLogCollection::make($paginate)->toArray(null);
        return $this->success('', $result);
    }

    /**
     * 登录日志列表
     * @param AdminLogFilter $filter
     * @return \Illuminate\Http\JsonResponse
     */
    public function login(AdminLogFilter $filter)
    {
        $paginate = AdminLog::leftJoin('user', 'admin_log.created_user_id', '=', 'user.id')->where('admin_log.type', 'login')->select(['admin_log.*'])->filter($filter)->paginate($this->pageSize());
        $result = AdminLogCollection::make($paginate)->only(['id', 'content', 'request_ip', 'request_browser', 'request_platform', 'response', 'status', 'created_user_name', 'created_at'])->toArray(null);
        return $this->success('', $result);
    }


}
